#ifndef xpack_test_lang_cxx_strcat
#define xpack_test_lang_cxx_strcat
#pragma push_macro("xuser")
#undef  xuser
#define xuser mixc::test_lang_cxx_strcat::inc
#include"test/helper.hpp" // 需要放第一
#include"lang/cxx/strcat.hpp"
#include"lang/cxx.hpp"
#include"memop/copy.hpp"
#pragma pop_macro("xuser")

namespace mixc::test_lang_cxx_strcat{
    xtest("strcat"){
        char buffer_a[128];
        char buffer_b[128];
        char * ptr_b        = buffer_b;
        auto value_a        = inc::c08{};
        auto value_b        = inc::c08{};
        auto alloc          = [&](uxx){
            return buffer_a;
        };
        auto stream         = [&](const char * buffer, uxx length){
            inc::copy_unsafe(ptr_b, buffer, length);
            ptr_b          += length;
        };

        #define xgen(fmt,...)                                                       \
        value_a             = inc::c08{fmt}.strcat(__VA_ARGS__, alloc);             \
                                                                                    \
        ptr_b               = buffer_b;                                             \
        inc::c08{fmt}.strcat(__VA_ARGS__, stream);                                  \
        value_b             = inc::c08(buffer_b, ptr_b - buffer_b)

        #define xgen_assert_eq(VAL)     \
            xassert_eq(value_a, VAL);   \
            xassert_eq(value_b, VAL)

        xgen(nullptr, { "world" });
        xgen_assert_eq("world");

        xgen("m", { "" });
        xgen_assert_eq("m");

        xgen("", { "m" });
        xgen_assert_eq("m");

        xgen("", { "world" });
        xgen_assert_eq("world");

        xgen("hello", { "" });
        xgen_assert_eq("hello");

        xgen("hello", { " world" });
        xgen_assert_eq("hello world");

        xgen("hello", { " world", " 2024" });
        xgen_assert_eq("hello world 2024");

        inc::c08 content = "2024";
        xgen("hello ", content);
        xgen_assert_eq("hello 2024");

        xgen("hello ", { content });
        xgen_assert_eq("hello 2024");

        xgen("hello", { " world ", content });
        xgen_assert_eq("hello world 2024");

        #undef xgen
        #undef xgen_assert_eq
    };
}

#endif